<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
      <el-form-item label="用户信息:" prop="member">
        <el-input
          size="mini"
          v-model="queryParams.member"
          placeholder="请输入邮箱/编号/姓名/昵称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单号:" prop="sn">
        <el-input
          size="mini"
          v-model="queryParams.sn"
          placeholder="请输入订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="卡号:" prop="cardNo">
        <el-input
          size="mini"
          v-model="queryParams.cardNo"
          placeholder="请输入卡号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="交易类型:" prop="type">
        <el-select v-model="queryParams.type" placeholder="请选择交易类型" clearable size="mini" @change="getList">
          <el-option v-for="dict in dict.type['card_transaction_type']"
                     :key="dict.value"
                     :label="dict.label"
                     :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="交易状态:" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择交易状态" clearable size="mini" @change="getList">
          <el-option v-for="dict in dict.type['transaction_status']"
                     :key="dict.value"
                     :label="dict.label"
                     :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="交易时间:">
        <el-date-picker
          v-model="dateRange"
          style="width: 240px"
          format="yyyy-MM-dd"
          value-format="timestamp"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="['00:00:00', '23:59:59']"
          size="mini"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="dataList">
      <el-table-column label="序号" type="index" align="center" min-width="5%"/>
      <el-table-column label="订单号" align="center" prop="sn" key="sn"/>
      <el-table-column label="卡号" align="center" prop="cardNo" key="cardNo">
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="goBankDetail(scope.row)"
          >
            {{ scope.row.cardNo }}
          </el-button>
        </template>
      </el-table-column>
      <el-table-column label="交易类型" align="center" prop="type" key="type">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.card_transaction_type" :value="scope.row.type"/>
        </template>
      </el-table-column>
      <el-table-column label="交易币种" align="center" prop="transactionCurrency" key="transactionCurrency"/>
      <el-table-column label="交易金额" align="center" prop="transactionAmount" key="transactionAmount"/>
      <el-table-column label="交易状态" align="center" prop="status" key="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.transaction_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="交易时间" align="center" prop="createTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="用户信息" align="center" prop="uid" key="uid">
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="goMemberDetail(scope.row)"
          >
            用户信息
          </el-button>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="goTransactionDetail(scope.row)"
            v-hasPermi="['system:cardTransaction:query']"
          >详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <member-detail ref="member-detail"/>
    <bank-detail ref="bank-detail"/>
    <transaction-detail ref="transaction-detail"/>
  </div>
</template>
<script>
import { transactionPageList } from "@/api/triones/interlaceCard";
import memberDetail from "@/views/triones/member/memberUser/memberDetail.vue";
import bankDetail from "@/views/triones/bankConnect/bankcards/bankDetail.vue";
import transactionDetail from "@/views/triones/bankConnect/bankCardAuth/transactionDetail.vue";
export default {
  name: "index",
  dicts: ['card_transaction_type','transaction_status'],
  components: { memberDetail,bankDetail,transactionDetail },
  data() {
    return {
      // 遮罩层
      loading: false,
      showSearch: true,
      total: 0,
      dateRange: [],
      dataList: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        member: undefined,
        cardNo: undefined,
        type: undefined,
        status: undefined,
        sn: undefined
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.loading = true;
      transactionPageList(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      })
    },
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    goMemberDetail(row) {
      this.$refs["member-detail"].show(row.uid);
    },
    goBankDetail(row) {
      this.$refs["bank-detail"].show(row.cid);
    },
    goTransactionDetail(row) {
      this.$refs["transaction-detail"].show(row.id);
    }
  }
}
</script>
<style scoped lang="scss">

</style>
